package com.web.kdl.pojo.Vo.site;

import com.web.kdl.pojo.Bo.MapSiteBo;
import lombok.Data;

import java.util.List;

/**
 * @Author： shulibin
 * @Date： 2025/11/5 16:12
 * @Describe：
 */
@Data
public class MapSiteVo {
    private double soc;
    private double sumSiteCap;

    // 计算站点SOC 和 系统容量
    public MapSiteVo(MapSiteBo mapSiteBo){
        this.sumSiteCap = mapSiteBo.getSumSiteCap();

        List<MapSiteBo.FlywheelCoreInfo> flywheelCoreInfoList = mapSiteBo.getFlywheelCoreInfoList();

        // 处理空列表或null的情况
        if (flywheelCoreInfoList == null || flywheelCoreInfoList.isEmpty()) {
            this.soc = 0.0;
            return;
        }

        double weightedSum = 0.0;  // SOC₁×E₁ + SOC₂×E₂ + ... + SOCₙ×Eₙ

        // 计算加权SOC总和
        for (MapSiteBo.FlywheelCoreInfo info : flywheelCoreInfoList) {
            double soc = info.getSoc();           // 获取SOC值
            double capacity = info.getFlywheelCap(); // 获取容量E值
            weightedSum += soc * capacity;        // 累加加权SOC
        }

        // 避免除零错误
        if (this.sumSiteCap == 0) {
            this.soc = 0.0;
        } else {
            this.soc = weightedSum / this.sumSiteCap;
        }
    }

}
